package com.ss.android.article.base.feature.feed.presenter;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import java.lang.ref.WeakReference;

public final class ArticleQueryHandler extends Handler {
    private final WeakReference<QueryCallback> mQueryCallbackRef;

    public ArticleQueryHandler(QueryCallback queryCallback) {
        super(Looper.getMainLooper());
        this.mQueryCallbackRef = new WeakReference(queryCallback);
    }

    public final void handleMessage(Message msg) {
        QueryCallback queryCallback = this.mQueryCallbackRef.get();
        if (queryCallback != null) {
            if (msg.what == 10
                    || msg.what == 11) {
                ArticleQueryObj articleQueryObj = (ArticleQueryObj) msg.obj;
                queryCallback.onFinishQuery( msg.what == 10, articleQueryObj);
            } else if (msg.what == 10012) {
                queryCallback.onStartQuery((ArticleQueryObj) msg.obj);
            }
        }
    }
}

